package chapter;

import java.io.File;

public class FileSecondTest {
	
	
	
	public long countFile(String dir)
	{
		long len=0;
		
		File fa=new File(dir);
		
	    
		if(fa.isFile()){
			len += fa.length();
		}
		else if(fa.isDirectory()){
			File[] files = fa.listFiles();
//			File[] thepath = fa.listRoots();
			
			for(int i=0;i<files.length;i++){
				
//				File[] path=File.listRoots();
//				File thepath[i]=path[i];
  //       System.out.println(thepath[i]);
			}
			
			for(int i=0;i<files.length;i++){
				if(files[i].isFile()){
					len += files[i].length();
					
			    	
				}
				else if(files[i].isDirectory()){
					String str = files[i].getAbsolutePath();
					
					len += countFile(str);
				}
			}
		}
		return len;
	
	}
	public static void main(String[]args){
		
		FileSecondTest fst=new FileSecondTest();
		
		System.out.println(fst.countFile("D:\\"));
		System.out.println((float)fst.countFile("D:\\")/1024/1024/1024+"G");
		
	}

}
